from sim_progress.Buff import Buff, JudgeTools, check_preparation


class LyconAdditionalAbility:
    def __init__(self):
        self.last_stun_statement = False
        self.action_stack = None
        self.enemy = None
        self.info_dict = None


class LyconAdditionalAbilityStunVulnerability(Buff.BuffLogic):
    """
    该buff的退出逻辑特殊，失衡结束就会直接退出。

    """

    def __init__(self, buff_instance):
        super().__init__(buff_instance)
        self.buff_instance: Buff = buff_instance
        self.xjudge = self.special_judge_logic
        self.xexit = self.special_exit_logic
        self.buff_0 = None
        self.record = None

    def get_prepared(self, **kwargs):
        return check_preparation(buff_instance=self.buff_instance, buff_0=self.buff_0, **kwargs)

    def check_record_module(self):
        if self.buff_0 is None:
            self.buff_0 = JudgeTools.find_exist_buff_dict(sim_instance=self.buff_instance.sim_instance)["莱卡恩"][
                self.buff_instance.ft.index
            ]
        if self.buff_0.history.record is None:
            self.buff_0.history.record = LyconAdditionalAbility()
        self.record = self.buff_0.history.record

    def special_exit_logic(self):
        """
        该buff和莱特的核心被动失衡时间延长是一样的，都是要在失衡期消失的时候检测退出。
        获取当前失衡值，和上一次失衡值对比。
        """
        self.check_record_module()
        self.get_prepared(enemy=1)
        if self.record.last_stun_statement and not self.record.enemy.dynamic.stun:
            self.record.last_stun_statement = self.record.enemy.dynamic.stun
            return True
        else:
            self.record.last_stun_statement = self.record.enemy.dynamic.stun
            return False

    def special_judge_logic(self, **kwargs):
        """
        进入机制。获取当前skillNode并且检测当前怪物的失衡状态，两者都符合才触发。
        """
        self.check_record_module()
        self.get_prepared(enemy=1, action_stack=1)

        skill_node = kwargs.get("skill_node", None)
        if skill_node is None:
            return False
        if "1141" in skill_node.skill_tag and self.record.enemy.dynamic.stun:
            return True
        else:
            return False
